package com.joint.web.action.app;

import com.fz.us.base.bean.BaseEnum.OrderType;
import com.fz.us.base.bean.Pager;
import com.joint.base.entity.module.Resume;
import com.joint.base.util.StringUtils;
import com.joint.core.service.common.ResumeBeanService;
import com.joint.web.action.BaseAction;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.struts2.convention.annotation.ParentPackage;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 后台Action类 - 履历Action
 * ============================================================================
 * 版权所有 2015 。
 * ----------------------------------------------------------------------------
 *
 * @author fallenpanda
 *
 * @version 1.0 2015-02-28 by fallenpanda
 */

@ParentPackage("app")
public class ResumeAction extends BaseAction {

    private static final long serialVersionUID = 6215180408155035142L;
    protected final static int LISTVIEW_DATATYPE_RESUME_TARGET = 0xF1;//履历 - 目标Id

    private Resume resume;
	private List<Resume> resumeList;

    @Resource
    private ResumeBeanService resumeBeanService;

    /**
     * 列表
     *
     * @return String
     * @throws Exception
     */
	public String getList() throws Exception {
        users = getRequestUsers();
        company = users.getCompany();
        if(company == null)
            return ajaxHtmlAppResult(0, "未找到用户所属企业！",null);

        pager = new Pager();
        pager.setPageNumber(pageIndex);// 页码
        pager.setPageSize(pageSize);// 页Size
        if(pageIndex == 0){
            pager.setPageNumber(1);// 页码
            pager.setPageSize(50);// 页Size
        }
        if(StringUtils.isNotEmpty(pageProperty)&& StringUtils.isNotEmpty(pageKeyword)){
            pager.setProperty(pageProperty);
            pager.setKeyword(pageKeyword);
        }
        pager.setOrderType(OrderType.desc);
        pager.setOrderBy("createDate");

        if(StringUtils.isNotEmpty(keyId)){
            if(catalog == LISTVIEW_DATATYPE_RESUME_TARGET){
                pager=  resumeBeanService.getTargetPager(pager, keyId);
            }
        }

        resumeList = (List<Resume>) pager.getList();
        if(resumeList == null){
            resumeList = new ArrayList<Resume>();
        }

        List<JSONObject> dataRows = new ArrayList<JSONObject>();
        Map<String, Object> data = new HashMap<String, Object>();

        for (Resume temp : resumeList) {
            Map<String, Object> tempMap = resumeBeanService.getListItemMap(temp);
            dataRows.add(JSONObject.fromObject(tempMap));
        }

        data.put("pageNum", pageIndex);//页数
        data.put("pageSize", resumeList.size());
        data.put("pageCount", pager.getPageCount());
        data.put("totalCount", pager.getTotalCount());
        data.put("dataRows", JSONArray.fromObject(dataRows));
        return ajaxHtmlAppResult(1, "", JSONObject.fromObject(data));
	}

}